;-----------------------------------------------------------------------
;
; Custom.inc	Copyright Sega Of America 1991
;		Developed by CTG
;
;	This file is used to access the data variables and main routines of
;	the game gear character editor.  DO NOT MODIFY THIS FILE, Any future
;	Changes to the GameGear character Editor will result in this file
;	being updated, so that you can simply re-compile with a new custom.inc
;	file.
;
;	For use with MASM 5.0 and above or TASM 1.0 and above.
;
;-----------------------------------------------------------------------

.286
HCALL	MACRO	ROUTINE
		mov	bx,offset ROUTINE
		db	0ffh,1eh,0,0	;call	Far ptr DS:InterfaceRet
ENDM

MouseCheck	macro	Addr,StartX,StartY,Width,Height
LOCAL	NotINSIDE
		mov	bx,StartX
		mov	ax,DS:[MouseX]
		cmp	ax,bx
		jl	NotInside

		add	bx,Width
		cmp	ax,bx
		jge	NotInside

		mov	bx,StartY
		mov	ax,DS:[MouseY]
		cmp	ax,bx
		jl	NotInside

		add	bx,Height
		cmp	ax,bx
		jge	NotInside
		jmp	Addr
NotInside:
ENDM



MaxCharacters	equ	2047
MaxBrushSize		equ	31*15*2	;Size of edit area.
SeqRecords	equ	32768
MovieLenArray	equ	SeqRecords + 34*(Size SeqHedr)
MovieJifArray	equ	MovieLenArray+70

SeqHedr	Struc		;34 Animation sequences

StartingFrame	dw	0
AnimFrames	db	0
AnimStatus	db	0
AnimHotX	dw	0
AnimHotY	dw	0
AnimName	db	'0123456789'
FrameChars	db	20 dup(0)
FrameJiffy	db	20 dup(0)

SeqHedr ends

HOSTDATA	Struc

	;DONT CALL INTERFACERET or HOSTSEG

InterFaceRet		dw	0	;How you interface to all the below commands.
HostSeg			dw	0	;DO NOT CALL.  NOT A ROUTINE.  THIS IS THE HOSTS CODE SEGMENT



;		These routines can be accessed by the HCALL macro


HideMouse		dw	0	;Remove mouse from display screen.
ShowMouse		dw	0	;Place mouse back on display screen.
GetMousePosition	dw	0	;Update mouse position on screen.
DrawCharAX		dw	0	;Draw Character AX at position ESDI
DrawEntireScreen	dw	0	;Updates entire character map window.
DrawEntireScreenAx	dw	0	;Updates any characters matching AX in the map window.
RedrawAll		dw	0	;Redraws the entire VGA display (Erasing any windows).
DrawSpriteAX		dw	0	;Draws character AX as a sprite at ESDI
DrawDimSpriteAX		dw	0	;Draws character AX as a dim sprite at ESDI
DrawAllSmallSeq		dw	0	;Draws all the small frames in the animation section.
PrintAxDecimal		dw	0	;Prints the value in AX to the screen at address TextPosition.
PrintSiAtDi		dw	0	;Prints the Zero terminated ascii string pointer to by SI to address DI
GetCharAxQ		dw	0	;Sees if CharacterNORM exists in the set, if so returns in AX its MAP value,
						;Otherwise it creates a new character and returns its value.
DrawAnimScreen		dw	0	;Redraws the animation window.
DrawEditBox		dw	0	;Redraws the EditBox indexed by EditIndex
DrawGalleryWindow	dw	0	;Redraws the gallery window.
DrawMagChar		dw	0	;Redraws the magnified character window.
FileRequestor		dw	0	;Brings up a file requestor (See GetSaveHandle or GetLoadHandle)
GetLoadHandle		dw	0	;Gets a DOS file handle with a file requestor for loading.  (See programmer docs.)
GetSaveHandle		dw	0	;Gets a DOS file handle to write to by using the file requestor.  (See programmer docs.)
GetBoxedInput		dw	0	;Inputs a string with a prompt.
FlipCharH		dw	0	;Flips the character pointed to BY DI and stores in SI  (Horizontally)
FlipCharV		dw	0	;Flips the character pointed to by DI and stores in SI	(Vertically)





HCODESEG	dw	0	;Hosts code address

CDATA		dw	0	;Character data segment
MDATA		dw	0	;Map data segment
CDATAJ		dw	0	;J-Screen character data
MDATAJ		dw	0	;J-Screen Map data
ImageOff	dw	0	;Offset where custom command loaded.
ImageSeg	dw	0	;Custom command Code segment
DiskSeg		dw	0	;Disk I/O segment 64K


FREQseg		dw	0	;File requestor segment
LoadSeg		dw	0	;PSP of host program

ScreenOffset		dw	0	;Should be 0

XScroll			dw	0	;Current Map X Scroll position.
YScroll			dw	0	;Current Map Y Scroll position.
VXChars			dw	0	;Visually displayable characters
VYChars			dw	0	;Visually displayable characters
XDISPMAX		dw	31
YDISPMAX		dw	15

CharacterMask		dw	0000011111111111b ;Mask used to index characters.

CharacterNORM		db	32 dup(0)	;Four character buffers.
CharacterH		db	32 dup(0)
CharacterV		db	32 dup(0)
CharacterHV		db	32 dup(0)

PrinterPort		dw	0		;Port address of com cable.

;		GG FILE HEADERS

;----------------------------------------------------------------
HeadStuff	db	'GG'	;Game gear token
TypeFile	db	'SA'	;Save all
CharacterCount	dw	0	;Count of how many		;
				;characters are being used.	;
MaxXChars		dw	31				;
MaxYChars		dw	15				;
			db	0				; Type is graphic for downloader
BrushCount		db	0
			db	0
;----------------------------------------------------------------;

;----------------------------------------------------------------
JHeadStuff	db	'GG'	;Game gear token
JTypeFile	db	'SA'	;Save all
JCharacterCount	dw	0	;Count of how many		;
				;characters are being used.	;
JMaxXChars		dw	31				;
JMaxYChars		dw	15				;
			db	0				;
JBrushCount	db	0					;
		db	0
;----------------------------------------------------------------;

;----------------------------------------
AnimHeadStuff	db	'GG'		;Game gear file type
AnimTypeFile	db	'AN'		;Animation file
AnimCCount	dw	0		;Character Count
;SequenceCount	label	word	;Number of sequences
DoubleHighFlag	db	0	;Sprites are in double high mode.
WithMovieFlag	db	0
EditFrame	dw	0		;
		db	3		;Download type
EditSeq		dw	0		;
;----------------------------------------


JPallete	db 96 dup(0)		;J Screen pallete
DefPallete	db 96 dup(0)		;Default pallete
DispPallete	db 96 dup(0)		;Current pallete

DimPallete	db	32*3 dup(0)	;Dimmed pallete of current.
Greys		db	32*3 dup(0)	;Grey pallete of current.

GGRAW	db	64 dup(0)			;Raw game gear pallete

BrushSize	dw	10 dup(0)		;X,Y dimentions of brushes
JBrushSize	dw	10 dup(0)		;X,Y dimentions of J screen brushes
BrushData	dw	10*MaxBrushSize dup(0)	;Character map for brushes
JBrushData	dw	10*MaxBrushSize dup(0)	;Character map for brushes

CharacterUsedMap	db	MaxCharacters dup(0)		;2048 byte buffer
CVALUES			dw	MaxCharacters dup(0)		;4096 byte buffer
CValuesR		dw	MaxCharacters dup(0)		;4096 byte buffer

ScanIndexTable	dw	200 dup(0)	;X times 320 Multiply table.

BrushIndex	dw	0		;Current brush selected.
EditIndex	dw	0		;Index for which edit window is being worked on
EditChar	dw	0,1		;Characters in EditBoxes
EditCharFlip	db	0,0		;Special bits on characters in EditBoxes.
MagChar		dw	0		;Magnified character
Pal1		db	0,0		;The current selected pallete1 colors
Pal2		db	0,0		;The current selected pallete2 colors
WindowChar	dw	0		;The top right character shown in the gallery

FindChar		dw	0	;
FlipMask		db	-1	;  RESERVED FOR USE BY
FlipCode		db	0	;  DRAWENTIRESCREENAX
CharacterAttr		db	0	;


GridOn			db	0	;Flag specifing if Grid mode is on in Editor
			db	0
EditFlag		db	-1	;Flag specifing Edit mode or Animation mode.
BrushFlag		db	0	;If we are in brush or character mode.
SetBitMode		db	0	;Flag if we are in Advanced Edit123Bits mode.


MousePtr	dw	0		;Index of 0,1,2,3,or 4 of type of MousePtr
MouseX		dw	0		;Latest mouse X position  (Updated by ...
MouseY		dw	0		;Latest mouse Y position   GetMousePosition)
Buttons		dw	0		;Mouse button status

SaveRequestor	db	0	;Set to -1 if its a save requestor and
ButtonCount	db	3	;(1 - 4) button count
Key1		db	'y'		;Key codes for buttons of file requestor
Key2		db	'c'
Key3		db	'n'

ButtonAction1	dw	0	;Ptr to code in HOST CS: to execute
ButtonAction2	dw	0	;When button is pressed in File Requestor
ButtonAction3	dw	0

ButtonIndex1	dw	0	;Ptr to text for type of button 1
ButtonIndex2	dw	0	;Ptr to text for type of button 2
ButtonIndex3	dw	0	;Ptr to text for type of button 3

SaveAbortFlag	db	0	;Set to -1 if save is to be aborted.
Handle		dw	0	;Save output handle
InputHandle	dw	0	;Load input handle, or -1 if not valid.
SearchCount	db	0		;0 = One type of extension, 1 = two types.
SearchString	dw	0,0,0,0		;Pointer to '*.EXT',0 type search extensions.

TextPosition	dw	0

PromptText	dw	0	;Offset of text to be printed in box by GetBoxedInput
MaxInputLength	db	0	;maximum input length for GetBoxedInput
InputArea	dw	0	;Offset of where to put response text.

;------------------------------------------------
SourceFlag		db	0	        ; These are loaded from GG.CFG
DevelFlag		db	-1		; 0 = GG Devel board, -1 = Link Cable GG
PortNum			db	1		; Parallel port # (Not address)
VDPMAPBits		db	512/8 dup(0)	; one bit for each character
;------------------------------------------------

MaxActorTable		db	32 dup(1)

HOSTDATA ENDS





